#pragma once

#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>

//该类的功能是将网络字节序转为主机字节序  将四字节风格IP 转为点分十进制
class InetAddr
{
public:
    
    InetAddr(const struct sockaddr_in& addr)
        :_addr(addr)
    {
        _port = ntohs(_addr.sin_port);//将网络序列转为系统默认序列
        _ip = inet_ntoa(_addr.sin_addr);//将4字节的风格的ip转为   点分十进制
    }

    std::string IP(){ return _ip;}
    uint16_t Port(){ return _port; }
private:
    std::string _ip;
    uint16_t _port;
    struct sockaddr_in _addr;
};